﻿using System.Collections.Generic;
using UnityEngine;

/*�ųǽ���*/

public class Test_Mathf : MonoBehaviour
{
    private float[] f = new float[] { 3, 4, 6, 7 };
    public float a = 15;

    private void Start1()
    {
        print(Mathf.Abs(-10));
        print(Mathf.Max(f));
        print(Mathf.Clamp(a, 5, 20));
        print(Mathf.Clamp01(a));
        print(Mathf.Lerp(3, 9, 0.5f));
        print(Mathf.InverseLerp(3, 9, 6));
        float b = 360 * Mathf.Deg2Rad;
        print(b);
        print(Mathf.PI * Mathf.Rad2Deg);
        print(Mathf.Sin(30 * Mathf.Deg2Rad));
        print(Mathf.Cos(60 * Mathf.Deg2Rad));
        print(Mathf.Tan(45 * Mathf.Deg2Rad));
        print(Mathf.Round(8.593f));
        print(Mathf.Repeat(9.87654f, 4));
        print(Mathf.PingPong(3.14f, 2));
        print(Mathf.Pow(2, 4));
    }

    private void Update3()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            float d = 360;//度
            print(d * Mathf.Deg2Rad);//
            print(Mathf.PI * Mathf.Rad2Deg);
            print(Mathf.Repeat(9.87654f, 8));
        }
    }

    //演示位置插值
    [Range(0, 1)]
    public float t;

    public Transform A, B, O;
    public AnimationCurve curve;//动画曲线，可以自己画

    private void Update1()
    {
        t += Time.deltaTime / 3;
        O.position = Vector3.Lerp(A.position, B.position, curve.Evaluate(t));
    }

    //用插值做缓动效果,O缓动到B
    private void Update2()
    {
        O.position = Vector3.Lerp(O.position, B.position, Time.deltaTime);
    }

    //动画曲线和插值
    //演示MoveTowards
    private void Update()
    {
        //让o匀速移动到b
        O.position = Vector3.MoveTowards(O.position, B.position, Time.deltaTime * 3);
    }
}